home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Magazine / C_Tutorial / Part-7 / arexx0 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-26  |  2.3 KB  |  111 lines

  1. #include<exec/libraries.h>
  2.  
  3. #include<stdio.h>
  4.  
  5. #include<clib/exec_protos.h>
  6.  
  7. #include "gui.h"
  8. #include "idcmp.h"
  9. #include "loadsave.h"
  10. #include "arexx.h"
  11.  
  12. /* The library base global variables */
  13. /* (The different style of opening libraries requires these to be initialised to NULL) */
  14. struct Library* GfxBase = NULL;
  15. struct Library* IntuitionBase = NULL;
  16. struct Library* GadToolsBase = NULL;
  17. struct Library* AslBase = NULL;
  18. struct Library* DosBase = NULL;
  19. struct Library* IFFBase = NULL;
  20. struct Library* RexxSysBase = NULL;
  21.  
  22. /* Need to give prototypes for our functions */
  23. int  createAll(void);
  24. void freeAll(void);
  25. int  openLibs(void);
  26. void closeLibs(void);
  27.  
  28. /* The initial screen depth */
  29. #define SCR_DEPTH (4)
  30.  
  31. /* The start of the program */
  32. void main()
  33. {
  34.     if(createAll())
  35.         handleIDCMP();
  36.     freeAll();
  37. }
  38.  
  39. int createAll()
  40. {
  41.     return openLibs() && createARexxPort("HELLOPAINTER") && openGUI(SCR_DEPTH,0,0,0);
  42. }
  43.  
  44. void freeAll()
  45. {
  46.     freeReqs();
  47.     closeGUI();
  48.     freeARexxPort();
  49.     closeLibs();
  50. }
  51.  
  52. /* Try to open all the libraries -- return TRUE on success */
  53. int openLibs()
  54. {
  55.     if((GfxBase = OpenLibrary("graphics.library",37)) == NULL)
  56.     {
  57.         printf("Error: could not open graphics.library\n");
  58.         return FALSE;
  59.     }
  60.     if((IntuitionBase = OpenLibrary("intuition.library",37)) == NULL)
  61.     {
  62.         printf("Error: could not open intuition.library\n");
  63.         return FALSE;
  64.     }
  65.     if((GadToolsBase = OpenLibrary("gadtools.library",37)) == NULL)
  66.     {
  67.         printf("Error: could not open gadtools.library\n");
  68.         return FALSE;
  69.     }
  70.     if((AslBase = OpenLibrary("asl.library",37)) == NULL)
  71.     {
  72.         printf("Error: could not open asl.library\n");
  73.         return FALSE;
  74.     }
  75.     if((DosBase = OpenLibrary("dos.library",37)) == NULL)
  76.     {
  77.         printf("Error: could not open dos.library\n");
  78.         return FALSE;
  79.     }
  80.     if((IFFBase = OpenLibrary("iff.library",23)) == NULL)
  81.     {
  82.         printf("Error: could not open iff.library\n");
  83.         return FALSE;
  84.     }
  85.     if((RexxSysBase = OpenLibrary("rexxsyslib.library",35)) == NULL)
  86.     {
  87.         printf("Error: could not open rexxsyslib.library\n");
  88.         return FALSE;
  89.     }
  90.   return TRUE;
  91. }
  92.  
  93. /* Close any open library */
  94. void closeLibs()
  95. {
  96.     if(RexxSysBase)
  97.         CloseLibrary(RexxSysBase);
  98.     if(IFFBase)
  99.         CloseLibrary(IFFBase);
  100.     if(DosBase)
  101.         CloseLibrary(DosBase);
  102.     if(AslBase)
  103.         CloseLibrary(AslBase);
  104.     if(GadToolsBase)
  105.         CloseLibrary(GadToolsBase);
  106.     if(IntuitionBase)
  107.         CloseLibrary(IntuitionBase);
  108.     if(GfxBase)
  109.         CloseLibrary(GfxBase);
  110. }
  111.